﻿<template>
    <el-dialog
        title="修改密码"
        v-model="visible"
        :width="700"
        destroy-on-close
        @closed="$emit('closed')"
    >
        <el-form
            :model="entityObj"
            :rules="rules"
            :disabled="mode == 'Show'"
            ref="dialogForm"
            autocomplete="off"
            label-width="100px"
        >
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="菜单编码" prop="menuCode">
                        <el-input v-model="entityObj.menuCode" />
                    </el-form-item>
                </el-col>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="菜单编码" prop="menuCode">
                        <el-input v-model="entityObj.menuCode" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="密码" prop="password">
                        <el-input v-model="entityObj.password" show-password autocomplete="off" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col :span="24">
                    <el-form-item label-width="120px" label="确认密码" prop="confirmPassword">
                        <el-input
                            v-model="entityObj.confirmPassword"
                            show-password
                            autocomplete="off"
                        />
                    </el-form-item>
                </el-col>
            </el-row>
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取 消</el-button>
            <el-button
                v-if="mode != 'show'"
                type="primary"
                :loading="isSaveing"
                @click="submit()"
            >保 存</el-button>
        </template>
    </el-dialog>
</template>

<script>
import tool from "@/utils/tool";
export default {
    emits: ["success", "closed"],
    data() {
        return {
            mode: "Add",
            entityObj: {
                status: 1,
            },
            visible: false,
            isSaveing: false,
            needSaveFlag: false,         
            //验证规则
            rules: {
                accountCode: [
                    { required: true, type: "string", message: "请填写" },
                ],
                password: [
                    { required: true, type: "string", message: "请填写" },
                ],
                confirmPassword: [
                    { required: true, type: "string", message: "请填写" },
                ],
                pid: [{ required: true, type: "number", message: "请填写" }],
                realName: [
                    { required: true, type: "string", message: "请填写" },
                ],
                mobile: [{ required: true, type: "string", message: "请填写" }],
                status: [{ required: true, type: "number", message: "请填写" }],
            },
        };
    },
    methods: {
        //显示=
        open(mode = "Add") {
            this.mode = mode;
            this.visible = true;
            return this;
        },
        //表单提交方法
        submit() {
            this.$refs.dialogForm.validate(async (valid) => {
                if (valid) {
                    this.isSaveing = true;
                    try {
                        if (this.entityObj.password != this.entityObj.confirmPassword) {
                            this.$message.success("输入的密码不一致");
                            return false;
                        }
                        var returnValue =
                            await this.$API.auth.PostProcessApi.post(
                                "account/passwrod",
                                { ...this.entityObj }
                            );
                        if (returnValue.status == 200) {
                            this.$message.success("操作成功");
                            this.$emit("fatherMethod");
                            this.isSaveing = false;
                            this.visible = false;
                        } else {
                            this.visible = false;
                            this.isSaveing = false;
                            this.$message.error("操作失败:" + returnValue.msg);
                        }
                    } catch (error) {
                        this.loading = false;
                        this.visible = false;
                        this.isSaveing = false;
                        return false;
                    }
                }
            });
        },
        //表单注入数据
        async setData(data) {
            this.entityObj = { ...data,password:"",confirmPassword:"" };
        },
    },
    async mounted() {
        //this.entityObj.orgName=tool.data.get("USER_INFO").OrgName;
        //await this.initOptions();
    },
};
</script>

<style></style>
